<template>
	<view class="pro_report">
		<view class="pro_nav">
			<text :class="['nav_item', currentNav == 1? 'curr_nav_item':'']" @click="changeNavItem(1)">待处理</text>
			<text :class="['nav_item', currentNav == 2? 'curr_nav_item':'']" @click="changeNavItem(2)">已完成</text>
		</view>
		<scroll-view class="pro_rep_list" scroll-y>
			<u-empty :show="showRepairs" mode="list"></u-empty>
			<view class="pro_rep_item" v-for="item in repairsList" :key="item.id" @click="goToReportDetails(item.id)">
				<view class="rep_top">
					<view class="re_fl">
						<!-- <image class="re_fl_img" :src="item.img[0]" mode=""></image> -->
						<text>{{item.type_text}}</text>
					</view>
					<view class="re_fr">{{item.status_text}}</view>
				</view>
				<view class="rep_con">
					<image class="rep_con_fl" :src='item.img[0]' mode=""></image>
					<view class="rep_con_fr">
						{{item.content}}
					</view>
				</view>
				<view class="rep_foo" @click.stop>
					<view class="rep_foo_fl">
						<image class="rep_foo_img" :src="avatarUrl" mode=""></image>
						<view class="foo_fl_name">
							<text>{{item.name}}提交</text>
							<text>{{item.created_at}}</text>
						</view>
					</view>
					<text class="rep_foo_fr" @click.stop="cancelWarr(item.id)">取消报修</text>
				</view>
			</view>
		</scroll-view>

		<view class="pro_addbtn">
			<image class="pro_addbtn_img" :src="'https://community.chuangxiangdianli.com/images/propertyImg/baoxiu_tu.png'" mode=""></image>
			<text class="pro_addbtn_txt" @click="goToAddReport">新增报修</text>
		</view>
	</view>
</template>

<script>
	import {
		getStorages
	} from '@/utils/storage'
	import {
		BASEIMGURL
	} from '@/utils/public'
	export default {
		data() {
			return {
				currentNav: 1,
				// 报修列表
				repairsList: [],
				// 头像图片
				avatarUrl: '',
				// 报修状态 0-待处理 1-已完成
				status: 0,
				// 列表数据是否为空
				showRepairs: false
			};
		},
		onShow() {
			if (getStorages('userInfo')) {
				this.avatarUrl = getStorages('userInfo').avatarUrl,
					this.nickName = getStorages('userInfo').nickName
			}
			this.getRepairs()
		},
		methods: {
			changeNavItem(index) {
				this.currentNav = index
			},
			// 前往保修详情
			goToReportDetails(id) {
				uni.navigateTo({
					url: '/property/reportDetails/index?id=' + id
				})
			},
			// 新增保修页面
			goToAddReport() {
				uni.navigateTo({
					url: '/property/addReport/index'
				})
			},
			// 获取列表
			getRepairs() {
				this.$mrequest2({
					url: 'Mini/Estate/repairs',
					method: 'GET',
					data: {
						status: this.status
					}
				}).then(res => {
					if (res.code == 200) {
						this.repairsList = res.data
						this.showRepairs = res.data.length == 0
					}
				})
			},
			// 取消保修
			cancelWarr(id) {
				this.$mrequest2({
					url: 'Mini/Estate/repairs/' + id,
					method: 'PUT',
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '取消成功',
							icon: 'none'
						})
						this.getRepairs()
					}
				})
			}
		},
		watch:{
			currentNav(num){
				if(num == 1){
					this.status = 0
					this.getRepairs()
				}else{
					this.status = 2
					this.getRepairs()
				}
			}
		}
	}
</script>

<style lang="scss">
	.pro_report {
		height: calc(100vh - 94rpx);
		background-color: #f7f8f9;

		.pro_nav {
			display: flex;
			height: 109rpx;
			line-height: 109rpx;
			background-color: #fff;

			.nav_item {
				margin: 0 100rpx;
				flex: 1;
				text-align: center;
			}

			.curr_nav_item {
				border-bottom: 3rpx solid #34B0FF;
			}
		}

		.pro_rep_list {
			padding: 0 30rpx 30rpx 30rpx;
			height: calc(100vh - 204rpx);
			overflow: hidden;

			.pro_rep_item {
				margin-top: 22rpx;
				width: 92%;
				font-size: 28rpx;
				background-color: #fff;
				border-radius: 20rpx;

				.rep_top {
					display: flex;
					justify-content: space-between;
					padding: 0 40rpx;
					height: 83rpx;
					line-height: 83rpx;
					font-weight: 700;
					border-bottom: 2rpx dashed #999;

					.re_fl {
						display: flex;

						.re_fl_img {
							margin: auto 20rpx auto auto;
							width: 47rpx;
							height: 46rpx;
						}
					}
				}

				.rep_con {
					display: flex;
					justify-content: space-between;
					padding: 34rpx 40rpx;
					height: 220rpx;

					.rep_con_fl {
						width: 180rpx;
						border-radius: 10rpx;
						background-color: #f4f4f4;
					}

					.rep_con_fr {
						width: 360rpx;
						line-height: 42rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 3;
						overflow: hidden;
					}
				}

				.rep_foo {
					display: flex;
					justify-content: space-between;
					padding: 18rpx 40rpx;
					height: 100rpx;

					.rep_foo_fl {
						display: flex;

						.rep_foo_img {
							margin-right: 16rpx;
							width: 70rpx;
							height: 70rpx;
							border-radius: 50%;
						}

						.foo_fl_name {
							display: flex;
							flex-direction: column;
							justify-content: space-between;
						}
					}

					.rep_foo_fr {
						height: 100%;
						width: 160rpx;
						height: 64rpx;
						text-align: center;
						line-height: 64rpx;
						background: #F4F4F4;
						border: 2rpx solid #D1D1D1;
						border-radius: 5rpx;
					}
				}
			}
		}

		.pro_addbtn {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 94rpx;
			text-align: center;
			line-height: 94rpx;
			color: #20A6FB;
			font-size: 34rpx;
			background-color: #fff;
			box-shadow: 0px 3rpx 3rpx 0px rgba(52, 176, 255, 0.09);

			.pro_addbtn_img {
				margin-right: 25rpx;
				width: 36rpx;
				height: 36rpx;
			}
		}
	}
</style>
